<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <title>操作员列表</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
		<link rel="stylesheet" type="text/css" href="../ext/ext-all.css" />
		<link rel="stylesheet" type="text/css" href="../ext/sms.css" />
		<script type="text/javascript" src="../ext/ext-base.js"></script>
		<script type="text/javascript" src="../ext/ext-all.js"></script>

	<style type="text/css">
	.ext-ie .x-menu-item-icon {left: -24px; top: 0px;}
	.ext-strict .x-menu-item-icon {left: 3px; top: 3px;}
	.ext-ie6 .x-menu-item-icon {left: -24px; top: 0px;}

.settings {
	background: url(../img/delete.gif) left top no-repeat !important;
	}
.settings_c {
	background: url(../img/cancle.gif) left top no-repeat !important;
	}

	</style>
	<script type="text/javascript">
	Ext.BLANK_IMAGE_URL = '../images/s.gif';
	</script>

	<script type="text/javascript">
	Ext.onReady(function(){
  		var sm = new Ext.grid.CheckboxSelectionModel();
	   sm.handleMouseDown = Ext.emptyFn;

	   var swin;
		var AdminRecord = Ext.data.Record.create([
	        {name: 'aid', type: 'string'},
	        {name: 'auname', type: 'string'},
	        {name: 'apwd', type: 'string'},
	        {name: 'acompany', type: 'string'},
	        {name: 'aregisttime', type: 'string'},
	        {name: 'arank', type: 'int'},
	        {name: 'asmsnum', type: 'int'},
	        {name: 'aavailable', type: 'int'},
            {name: 'aaddress', type: 'string'},
            {name: 'aphone', type: 'string'},
            {name: 'alinkman', type: 'string'},
            {name: 'alinkmanphone', type: 'string'},
            {name: 'alinkmanqq', type: 'string'},
            {name: 'adefaultchannel', type: 'string'}

    ]);

    var store = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../ajaxjsp/operatorlist.jsp'}),
        reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'result'
        },AdminRecord),
        remoteSort: true
    });


    var columns = new Ext.grid.ColumnModel([
        new Ext.grid.RowNumberer(),
        sm,
        {header: '用户名', dataIndex: 'auname'},
        {header: '注册日期', dataIndex: 'aregisttime'},
        {header: '联系电话', dataIndex: 'alinkmanphone'},
        {header: '联系QQ',dataIndex: 'alinkmanqq'},
        {header: '修改密码',dataIndex:"changepwd",width:70,align:'center',renderer:cpbutton}
    ]);

	function cpbutton(value,c){
	  var returnStr;
      returnStr = " <button class='btn3_mouseout test' onmouseover=\"this.className='btn3_mouseover test'\" onmouseout=\"this.className='btn3_mouseout test'\" onmousedown=\"this.className='btn3_mousedown test'\" style='cursor: hand;'>修改密码</button>";
	  return returnStr;
	}
       columns.defaultSortable = true;

        var grid = new Ext.grid.GridPanel({
        title: '操作员列表',
        region: 'center',
        loadMask: true,
        store: store,
        cm: columns,
        sm: sm,
        viewConfig: {
        columnsText:'显示的列',
        sortAscText:'升序',
        sortDescText:'降序',
        forceFit: true
        },
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: store,
            displayInfo: true,
            displayMsg: '显示 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg:'没有记录'

        }),
        tbar: new Ext.Toolbar({
        items:[
        '-',
               {
                    id:'del'
                    ,text:"删除"
                     ,iconCls:'settings'
                    ,handler: function(){
                    doGrid();
                    }
                },'-'

            ]
        })
    });

    store.load({params:{start:0,limit:15}});
    grid.on('cellclick',function (ngrid, rowIndex, columnIndex, e){
    var record = ngrid.getStore().getAt(rowIndex);   //Get the Record
    var fieldName = ngrid.getColumnModel().getDataIndex(columnIndex); //Get field name

   	if(fieldName == 'changepwd'){
   	var w = showmywindow(getchangepwdForm(record.get('aid')),'密码修改',250,180);
   	w.show();
   	}

    });

	function showmywindow(obj,t,w,h){
	var tw;
	var th;

	if(w==undefined){
		tw = 500;
	}else{
		tw = w;
	}
	if(h==undefined){
		th = 300;
	}else{
		th = h;
	}

	 swin = new Ext.Window({
		title : t,
		width    : tw,
		height   : th,
		layout   : 'fit',
		//applyTo : 'panel123',
		closeAction :'close',
		items    : [obj],
		bbar    : [
			'->',
			{
			text    : '关闭',
			handler : function() {
					swin.close();

				}
			}

		]
	});
	return swin;
	}

	var viewport = new Ext.Viewport({
	renderTo:'mt',
	layout:'border',
	items:[
	grid,
	{region:'south',contentEl:'inp',heigth:40}
	//{region:'east',html:'east',width:'30%'}
	]
	});


function getchangepwdForm(userid){
var pwdform = new Ext.FormPanel({
        labelWidth: 80, // label settings here cascade unless overridden
        url:'../ajaxjsp/proxyeditor.jsp?flag=changepassword&userid='+userid,
        frame:true,
        bodyStyle:'padding:5px 5px 0',
        defaultType: 'textfield',

        items: [

             {
                fieldLabel: '新密码',
               // width : '80%',
                name :'pwd',
                allowBlank:false,
                blankText :'密码必须填写'
            },{
                fieldLabel: '重复新密码',
               // width : '80%',
                 name :'npwd',
                allowBlank:false,
                blankText :'密码必须填写'
            }

            ],
            buttons: [{
            text: '修改',
            handler : function(){pwdform.form.submit({
					waitMsg : '正在处理......',
					success : function(form, action) {
						Ext.Msg.alert('成功',">>>>"+action.result.msg+"<<<<");
						swin.close();
					}
					,
					failure : function(form, action) {
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							Ext.MessageBox.alert('错误',action.result.errors.msg);}else{
							Ext.MessageBox.alert('错误','---------非法输入---------');
							}
					}
				});
            }
        }]
            });
       return pwdform;
}


	function doGrid(){
        var rows = grid.getSelectionModel().getSelections();
        if (rows.length == 0) {
            Ext.MessageBox.alert('错误', '最少选择一条信息，进行操作!');
        }
        else {
       		var names='';
                    for (var i = 0; i < rows.length; i++) {
                        names=names+rows[i].get('auname')+',';
                    }
            Ext.MessageBox.confirm('警告', '您确定要进行业务员删除操作吗？<br>即将删除的业务员为【'+names+'】<br>该删除将会删除如下说明：<br><br>1、删除该业务员。<br>2、删除该业务员与用户的关联信息。', function(btn){
                if (btn == 'yes') {
                var delid='';
                    for (var i = 0; i < rows.length; i++) {
                        delid=delid+rows[i].get('aid')+'^';
                    }
                 Ext.Ajax.request({
                  url : '../ajaxjsp/system.jsp?flag=deloperator',
                  method : 'POST',
                  params : {
                      delid : delid
                  },
                  success: function(response, options) {
                        //获取响应的json字符串
                       var responseArray = Ext.util.JSON.decode(response.responseText);
                            if(responseArray.success==true){
                            	 Ext.Msg.alert('成功','操作成功');
								 grid.getStore().reload();
                            }
                            else{
                                Ext.Msg.alert('失败','删除操作失败');
                            }
                         }
              });
                }
            });
        }
    }

});
	</script>
  </head>

  <body>
   <div id="mt"></div>
   <div id="north1"></div>
   <div id="south"></div>
    <div id="wait" align="center"></div>
   <input id="inp" value="刷新页面" type="button" onclick="javascript:window.location.reload();"></input>
  </body>
</html>
